using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;

namespace Microsoft.Samples.BizTalk.Adapter.Tcp.Send
{
    /// <summary>
    ///     This class represents a work item used to resolve a duplex listener and send the data onto it.
    /// </summary>
    /// <author>
    ///     Paul Brown
    /// </author>
    public class DuplexWorkItem : IWorkItem
    {
        #region Private Instance Members

        private WorkItemStatusTypes _status;            // The status of the work item
        private SendLocation        _sendLocation;      // The send location containing the message to transmit

        #endregion

        #region Constructor

        /// <summary>
        ///     This constructor initializes the class.
        /// </summary>
        public DuplexWorkItem(SendLocation sendLocation)
        {
            // Validate arguments
            if (sendLocation == null) throw new ArgumentNullException("sendLocation");

            // Initialize members
            this._status = WorkItemStatusTypes.Ready;
            this._sendLocation = sendLocation;
        }

        #endregion

        #region Public Instance Methods

        /// <summary>
        ///     This property returns the send location containing the message to be transmitted and the properties
        ///     controlling that transmission.
        /// </summary>
        public SendLocation SendLocation
        {
            get { return (this._sendLocation); }
        }

        #endregion

        #region IWorkItem Members

        #region Public Instance Properties

        /// <summary>
        ///     This property gets or sets the status of the work item.
        /// </summary>
        public WorkItemStatusTypes Status
        {
            get { return (this._status); }
            set { this._status = value; }
        }

        #endregion

        #region Public Instance Methods

        /// <summary>
        ///     This method saves the content of the work item to the folder location specified by the adapter.
        /// </summary>
        public void Save()
        {
            // Do nothing - if the worker thread is unable to resolve the BizTalk Party duplex listener address then
            // BizTalk will still hold the transmit message in the message box as we haven't transmitted it.
        }

        #endregion

        #endregion
    }
}
